<template>
  <div v-loading="loading" class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('投资项目信息') }}</span>
    </div>
    <el-form ref="queryForm" :model="fundPage" :inline="true">
      <el-form-item :label="$t('项目名称')" prop="dealName">
        <el-input
          v-model="fundPage.dealName"
          :placeholder="$t('项目名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('项目类型')" prop="dealType">
        <dict-select
          v-model="fundPage.dealType"
          dictionary="deal_type"
          :placeholder="$t('项目类型')"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>
    <div class="area-header">
      <span class="area-header-title">{{ $t('已投资基金列表') }}</span>
    </div>
    <el-table :data="fundList" border :show-summary="true" :summary-method="getFundSummaries">
      <el-table-column :label="$t('基金名称')" prop="fundName" align="center" show-overflow-tooltip />
      <el-table-column :label="$t('项目名称')" prop="dealName" align="center" show-overflow-tooltip />
      <el-table-column :label="$t('标的公司名称')" prop="companyName" align="center" show-overflow-tooltip />
      <el-table-column :label="$t('项目类型')" prop="dealType" align="center" :formatter="dealTypeFormat" />
      <el-table-column :label="$t('投资金额') + $t('金额单位')" prop="investAmount" align="center">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.investAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目负责人')" prop="personChargeName" align="center" />
      <el-table-column :label="$t('项目阶段')" prop="dealStage" align="center" />
    </el-table>
    <pagination
      v-show="fundTotal>0"
      :total="fundTotal"
      :page.sync="fundPage.pageNum"
      :limit.sync="fundPage.pageSize"
      @pagination="findFundInvestProject"
    />
    <div class="area-header">
      <span class="area-header-title">{{ $t('已投资合伙企业列表') }}</span>
    </div>
    <el-table :data="hhqyList" border :show-summary="true" :summary-method="getHhqySummaries">
      <el-table-column :label="$t('合伙企业名称')" prop="hhqyName" align="center" show-overflow-tooltip />
      <el-table-column :label="$t('项目名称')" prop="dealName" align="center" show-overflow-tooltip />
      <el-table-column :label="$t('标的公司名称')" prop="companyName" align="center" show-overflow-tooltip />
      <el-table-column :label="$t('项目类型')" prop="dealType" align="center" :formatter="dealTypeFormat" />
      <el-table-column :label="$t('投资金额') + $t('金额单位')" prop="investAmount" align="center">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.investAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目负责人')" prop="personChargeName" align="center" />
      <el-table-column :label="$t('项目阶段')" prop="dealStage" align="center" />
    </el-table>
    <pagination
      v-show="hhqyTotal>0"
      :total="hhqyTotal"
      :page.sync="hhqyPage.pageNum"
      :limit.sync="hhqyPage.pageSize"
      @pagination="findHhqyInvestProject"
    />
  </div>
</template>

<script>
import { findFundInvestProject, getFundSum, getHhqySum } from '@/api/fund/gp/gpBase'
import { findHhqyInvestProject } from '@/api/fund/gp/gpBase'
export default {
name: 'InvestProjectInfo',
  data() {
    return {
      fundList: [],
      hhqyList: [],
      // 基金查询参数
      fundPage: {
        gpId: this.$route.query.id,
        dealName: undefined,
        dealType: undefined,
        pageNum: 1,
        pageSize: 10
      },
      fundSumForm: {},
      hhqySumForm: {},
      // 遮罩层
      loading: false,
      fundTotal: 0,
      // 合伙企业查询参数
      hhqyPage: {
        gpId: this.$route.query.id,
        dealName: undefined,
        dealType: undefined,
        pageNum: 1,
        pageSize: 10
      },
      hhqyTotal: 0,
      // 项目类型字典
      dealTypeOptions: []
    }
  },
  created() {
    this.getList()
    this.getDicts('deal_type').then(response => {
      this.dealTypeOptions = response.data
    })
  },
  methods: {
    getList: async function() {
      this.loading = true
      await this.findFundInvestProject()
      await this.findHhqyInvestProject()
      this.loading = false
    },
    findFundInvestProject: async function() {
      await findFundInvestProject(this.fundPage).then(response => {
        this.fundList = response.rows
        this.fundTotal = response.total
        getFundSum({ gpId: this.$route.query.gpId, dealName: this.fundPage.dealName, dealType: this.fundPage.dealType }).then(res => {
          this.fundSumForm = res.data
        })
      })
    },
    findHhqyInvestProject: async function() {
      await findHhqyInvestProject(this.hhqyPage).then(response => {
        this.hhqyList = response.rows
        this.hhqyTotal = response.total
        getHhqySum({ gpId: this.$route.query.gpId, dealName: this.hhqyPage.dealName, dealType: this.hhqyPage.dealType }).then(res => {
          this.hhqySumForm = res.data
        })
      })
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.fundPage.pageNum = 1
      this.hhqyPage.pageNum = 1
      this.hhqyPage.dealName = this.fundPage.dealName
      this.hhqyPage.dealType = this.fundPage.dealType
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    // 是否分给配LP 系统是否字典翻译
    dealTypeFormat(row) {
      return this.selectDictLabel(this.dealTypeOptions, row.dealType)
    },
    getFundSummaries(param) {
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
        } else if (index === 4) {
          sums[index] = this.moneyFormat(this.fundSumForm.investAmount, 'w')
        } else {
          sums[index] = ''
        }
      })
      return sums
    },
    getHhqySummaries(param) {
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
        } else if (index === 4) {
          sums[index] = this.moneyFormat(this.hhqySumForm.investAmount, 'w')
        } else {
          sums[index] = ''
        }
      })
      return sums
    }
  }
}
</script>

<style scoped>

</style>
